package com.xja.contriller;

import com.xja.entity.BookType;
import com.xja.service.BookTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("bookType")
public class BookTypeController {
    @Autowired
    private BookTypeService bookTypeService;

    @RequestMapping("find")
    public String find(Model model){
        try {
            List<BookType> bookTypeList=bookTypeService.findBookTypes();
            System.out.println("========+bookTypeList"+bookTypeList);
            model.addAttribute("bookTypeList",bookTypeList);
            return "type_list";
        }catch (Exception e){
            e.printStackTrace();
        }
        return "error";
    }

    //添加
    public String add(HttpServletRequest req, HttpServletResponse resp) {
            try {
                String typeName=req.getParameter("typeName");
                BookType bookType = new BookType();
                bookType.setTypeName(typeName);
                bookTypeService.insert(bookType);
              //resp.sendRedirect("/bookType?method=add");
               return "add";
            }catch (Exception e){
                e.printStackTrace();
            }
        return "error";
    }

    public static void main(String[] args) {
        System.out.println("你好");
    }

//随便写个东西
    public String add1() {
        return null;
    }
}
